<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><s:text name="grantsetting.grantsetting.title"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script type="text/javascript" src="http://kjgl.ahinfo.org.cn/egrantres/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="http://kjgl.ahinfo.org.cn/egrantres/js/tooltips/tooltips.js"></script>
<script type="text/javascript" src="http://kjgl.ahinfo.org.cn/egrantres/js/jquery/wBox/wbox.js"></script>
<link rel="stylesheet" type="text/css" href="http://kjgl.ahinfo.org.cn/egrantres/js/jquery/wBox/wbox.css" />
<link rel="stylesheet" type="text/css" href="http://kjgl.ahinfo.org.cn/egrantres_app/css/public.css" />
<script type="text/javascript" src="http://kjgl.ahinfo.org.cn/egrantres/js/jquery/jquery.js"></script>
<style type="text/css">
.Explanation_Box{ background-color:#ffe6d4; width:400px; height:auto; border:1px solid #dc842e; position:absolute; bottom:25px; z-index:999999; color:#333;}
.Explanation_contant{ padding:10px; line-height:18px;}
.Cutting_head{ background:url(${res}/images/icon_jiantou03.gif) no-repeat; width:11px; height:7px; position:absolute; bottom:-7px;  _bottom:-14px; left:180px;}
.Condition{ width:500px;position:absolute;bottom:-1px;}

</style>
</head>

<body >
	<form id="prpForm" method="post" >
		<input type="hidden" id="grantCode" name="grantCode" />
		<input type="hidden" id="subGrantCode" name="subGrantCode" />
		<input type="hidden" id="helpGrantCode" name="helpGrantCode" />
		<input type="hidden" id="oc" name="oc"  value="<iris:des3 code="${oc }" />"/>
	</form>

	<%-- 
	<cpt:helpTips key="" id=""></cpt:helpTips>
	<div class="clear_h15"></div>
	 --%>

	<div class="word_box">
		<div id="tabnav1">
			<span class="t_flag left">请选择相应类别进行申请</span>
		</div>
			<div class="tab_sort" style="display:none;">
			<ul>
				<c:forEach items="${grantList}" var="vo" varStatus="varStatus" begin="0" end="11" step="1">
					<c:choose>
					<c:when test="${varStatus.first and (empty count or count==0)}">
						<li id="tab-${vo.zeroLevelMap.grantCode}" onclick="changeTab(this.id);" class="down">
							<a href="#"><span>${vo.zeroLevelMap.grantName}</span></a>
						</li>
					</c:when>
					<c:otherwise>
							<li id="tab-${vo.zeroLevelMap.grantCode}" onclick="changeTab(this.id);">
								<a href="#"><span>${vo.zeroLevelMap.grantName}</span></a>
							</li>
					</c:otherwise>
					</c:choose>
				</c:forEach>
			</ul>
			</div>
			<div class="tab_sort2" style="display:none;">
			<ul >
				<c:forEach items="${grantList}" var="vo" varStatus="varStatus" begin="12"  step="1">
					<c:choose>
					<c:when test="${varStatus.first and (empty count or count==0)}">
						<li id="tab-${vo.zeroLevelMap.grantCode}" onclick="changeTab(this.id);" >
							<a href="#"><span>${vo.zeroLevelMap.grantName}</span></a>
						</li>
					</c:when>
					<c:otherwise>
							<li id="tab-${vo.zeroLevelMap.grantCode}" onclick="changeTab(this.id);">
								<a href="#"><span>${vo.zeroLevelMap.grantName}</span></a>
							</li>
					</c:otherwise>
					</c:choose>
				</c:forEach>
			</ul>
		</div>
		<div class="clear" style="height:1px; overflow:hidden;"></div>
		<c:forEach items="${grantList}" var="vo1" varStatus="varStatus">
			<table id="fragment-tab-${vo1.zeroLevelMap.grantCode}" border="0" cellspacing="0" cellpadding="0" class="table03" <c:if test="${!varStatus.first}">style="display:none"</c:if>>
				<tr class="bg_a">
					<td width="27%">项目类别</td>
					<td width="23%">申请起止时间</td>
					<td width="8%" nowrap>申报书样本</td>
					<td width="32%" nowrap>依据条款</td>
					<td width="10%">操作</td>
				</tr>
				<tr class="bg_b">
					<td colspan="5"></td>
				</tr>
				
				<c:forEach items="${vo1.firstLevelList}" var="vo">
					<c:choose>
					
						<c:when test="${vo.childrenCount==0 && vo1.zeroLevelMap.grantCode!=0}">
						
						</c:when>
						<c:when test="${vo.childrenCount_cando==0 && vo1.zeroLevelMap.grantCode==0}">
						
						</c:when>
						<c:otherwise>
							<c:set var="prpFlag" value="1"/>
							<tr id="tr_${vo.grantCode}_${vo1.zeroLevelMap.grantCode}" class="bg_c"  onclick="showChildGrant('${vo1.zeroLevelMap.grantCode}','${vo.grantCode}')">
								<td nowrap><a href="###" class="b_Close" id="name_${vo.grantCode}_${vo1.zeroLevelMap.grantCode}" >${vo.grantName}</a></td>
								<td class="num" align="center">
								</td>
								<td id="pdf_${vo.grantCode}">
									<span></span>
								</td>
								<td id="tips_${vo.grantCode}">
									<span></span>
								</td>
								
								<td>
									<input type="button" class="btn_zk" title="展开" id="btn_${vo.grantCode}_${vo1.zeroLevelMap.grantCode}" />
									<!-- <script>$(document).ready(function(){showChildGrant('${vo.grantCode}','${prpFlag}');});</script>--> 
								</td>
							</tr>
						</c:otherwise>
					</c:choose>
				</c:forEach>
			</table>
		</c:forEach>
		
	</div>

<script type="text/javascript">
	$.ajaxSetup ({
	    cache: false //关闭AJAX相应的缓存
	});
	$(function(){
		queryflex();
		updateTabView();
		//changeTab('tab-1');
		/*$("table[id^='fragment-tab-']").each(function(){

			$(this).find("tr:eq(2)").click();
		});*/
	});
	var prcWin = new progressWin("${res}");//初始化遮罩层
	function enterPrp(grantCode,subGrantCode,prpFlag) {
		 var role ='${requestScope.role}';
		 var count ='${requestScope.count}';
		//alert(subGrantCode);
		//不是单位实训导师或者不具有填写实训导师资格的单位不能填写人才实训申请书
	    if(subGrantCode=='102' && (role!='27') && (count=='0')){
			 alert("你不能填写该类别的申请书！！！");
			 return false;
		 }
	    //单位实训导师只能填写人才实训申报书
		if(subGrantCode!='102' && (role=='27')){
			 alert("你不能填写该类别的申请书！！！");
			 return false;
		}
	    if((role=='3') && (count!='0') && subGrantCode=='102'){
	    	 alert("你不能填写该类别的申请书！！！");
			 return false;
	    }
	    
	    //单位管理员不能代填奖励申请书
	    if((role=='26') && (subGrantCode =='2513' ||subGrantCode =='2514' ||subGrantCode =='2515' ||subGrantCode=='916')){
	    	 alert("请以项目负责人角色登录系统，填写申报奖项！");
			 return false;
	    }
		if(prpFlag=='0')
		{
			//scmWarn("申报未开放");
			tb_show("违反申请条件", ctx + "/proposal/edit/dialog/prprules_errs?errList=网上申请尚未开放"
					+ "&TB_iframe=true&height=200&width=600", false);
			return false;
		}
		if(prpFlag=='2')
		{
			//scmWarn("申报已过期");
			tb_show("违反申请条件", ctx + "/proposal/edit/dialog/prprules_errs?errList=网上申请已过期"
					+ "&TB_iframe=true&height=200&width=600", false);
			return false;
		}
		$("#grantCode").val(grantCode);
		$("#subGrantCode").val(subGrantCode);
		
		if(subGrantCode==null || $.trim(subGrantCode)=="")
			subGrantCode = grantCode;
		
		var oc = "<iris:des3 code='${oc }' />";//授权单位code
		$.ajax({
			url:"${ctx}/grantsetting/validate-grant",
			data:{"grantCode":subGrantCode,"oc":oc},
			dataType: "text",
			type: "post",
			success:function(msg){
			 if(msg!=null&&msg!=""){//如果违反了申请条件
					tb_show("违反申请条件", ctx + "/proposal/edit/dialog/prprules_errs?errList="+encodeURIComponent(msg) 
							+ "&TB_iframe=true&height=200&width=600", false);
				}else{//符合申请条件 */
					$("#prpForm").attr("action","${ctx}/proposal/enter-prp?orgCode=${param.orgCode}");
					$("#prpForm").submit();
				} 
			}
			
		});
		/* <security:authorize ifNotGranted="A_DAILU_PROPOSAL">
 		$.ajax({
				url:"${ctx}/grantsetting/validate-grant",
				data:"grantCode="+subGrantCode,
				success:function(msg){
					if(msg!=null&&msg!=""){//如果违反了申请条件
						tb_show("违反申请条件", ctx + "/proposal/edit/dialog/prprules_errs?errList="+ msg
								+ "&TB_iframe=true&height=200&width=600", false);
					}else{//符合申请条件
						
						$("#prpForm").attr("action","${ctx}/proposal/enter-prp");
						$("#prpForm").submit();
					}
				}
				
			});
		</security:authorize>
		<security:authorize ifAnyGranted="A_DAILU_PROPOSAL">
			$("#prpForm").attr("action","${ctx}/proposal/enter-prp");
			$("#prpForm").submit();
		</security:authorize>  */
		
	}
	
	/**
	 * 展示资助类别能够填写的子类别
	 */
	function showChildGrant(grandParentCode,parentCode,prpFlag) {

		var trObj = $("#tr_"+parentCode+"_"+grandParentCode);
		if(trObj.attr("init") == "1"){						//如果已经加载过
			if(trObj.attr("openFlag") == "1"){				//关闭子类
				$("#name_"+parentCode+"_"+grandParentCode).each(function(){
					if($(this).attr("class").indexOf("_julei")==-1)
						$(this).attr("class","b_Close");
					else
						$(this).attr("class","b_Close_julei");
					});;
				$("#btn_"+parentCode+"_"+grandParentCode).attr("class","btn_zk");
				$("#btn_"+parentCode+"_"+grandParentCode).attr("title","展开");
				$("tr[parentCode='" + parentCode + "'][grandParentCode='" + grandParentCode + "']").hide();
				$("tr[grandParentCode='" + parentCode + "']").hide();
				$("[id^='name_'][id$='"+parentCode+"']").each(function(){
					if($(this).attr("class").indexOf("_julei")==-1)
						$(this).attr("class","b_Close");
					else
						$(this).attr("class","b_Close_julei");
					});
				$("[id^='btn_'][id$='_"+parentCode+"']").attr("title","展开");
				$("[id^='btn_'][id$='_"+parentCode+"']").attr("class","btn_zk");
				$("[id^='tr_'][id$='_"+parentCode+"']").attr("init","0");
				$("[id^='tr_'][id$='_"+parentCode+"']").attr("openFlag","0");
				trObj.attr("openFlag","0");
			} else {										//打开子类
				$("#name_"+parentCode+"_"+grandParentCode).each(function(){
					if($(this).attr("class").indexOf("_julei")==-1)
						$(this).attr("class","b_Open");
					else
						$(this).attr("class","b_Open_julei");
					});
				$("#btn_"+parentCode+"_"+grandParentCode).attr("class","btn_gb");
				$("#btn_"+parentCode+"_"+grandParentCode).attr("title","收缩");
				$("tr[parentCode='" + parentCode + "'][grandParentCode='" + grandParentCode + "']").show();
				trObj.attr("openFlag","1");
			}
			return;
		}
		
		prcWin.openWin();// 打开遮罩层
		$.ajax({
			type : "post",
			url : ctx + "/grantsetting/get-child-enabled",
			dataType : "json",
			data : "parentCode=" + parentCode+"&grandParentCode=" + grandParentCode + "&oc="+ $("#oc").val(),
			success : function(data) {
				if(data==null || data=="")
					return;
				
				var tr="";
				
				for ( var i = 0; i < data.length; i++) {
					var vo = data[i];
					if(data[i].hasChild==0){
						tr += "<tr parentCode=\'" + parentCode + "' grandParentCode='" + grandParentCode + "'>";
						if(data[i].grantLevel == 3){
							tr += "<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"b_li\">" + vo.grantName + "</span>"+"</td>";
						}else{
							tr += "<td nowrap><span class=\"b_li\"><b>" + vo.grantName + "<b></span>"+"</td>";
						}
						tr += "<td align=\"center\" class=\"num\">";
						
						
						//if(vo.startDateLong){
						if(vo.startDateLong){
							 tr +=vo.startDate + "～" + vo.endDateLong; 
							var flag=1;
							if(vo.startDate>vo.currentDate ){
								tr +="<font color='red'>（未开放申请）</font>";
								flag=0;
							}
							else
							if(vo.endDateLong<vo.currentDateLong){
								tr +="<font color='red'>（已过期）</font>";
								flag =2;
							}
						}else
							tr +="待定";
						
						
						
						tr += "</td>";//lwy 2012.5.19
						//tr += "<td class=\"num\">&nbsp;</td>";
						tr +="<td align=\"center\">";
						if(vo.sample_pdf!=null || vo.sample_pdf_code !=null){
							if(vo.sample_pdf_code!=null){
								tr +=" <a href=\"#\" class=\"uibtn pdf\" onclick=\"return downLoadRes('${ctx}"+"\/file\/ajax-filedownload?fileCode="+ vo.sample_pdf_code +"');\" title=\"PDF样本\"><span style=\"width:16px; height:16px; display:inline-block; cursor:pointer;background:url(${res_app}/images/hainan/ico_pdf.gif) no-repeat;padding-left:5px;\"></span><\/a>";
							}
							else{ 
								if(vo.sample_pdf !=null){
									tr +="<a href=\"#\"  onclick=\"return showRes('"+ vo.sample_pdf +"');\" title=\"PDF样本\"><span style=\"width:16px; height:16px; display:inline-block; cursor:pointer;background:url(${res_app}/images/hainan/ico_pdf.gif) no-repeat;padding-left:5px;\"></span><\/a>";
								}
							}
							if(vo.sample_word_code!=null){
								tr +="<a href=\"#\" class=\"uibtn word\" onclick=\"return downLoadRes('${ctx}"+"\/file\/ajax-filedownload?fileCode="+ vo.sample_word_code +"');\" title=\"word样本\"><span style=\"width:16px; height:16px; display:inline-block; cursor:pointer;background:url(${res_app}/images/hainan/ico_word.gif) no-repeat;padding-left:5px;\"></span><\/a>";
							}
							else{
								if( vo.sample_word!=null){
								tr +="<a href=\"#\" class=\"uibtn word\" onclick=\"showRes('"+vo.sample_word+"');\" title=\"word样本\"><span style=\"width:16px; height:16px; display:inline-block; cursor:pointer;background:url(${res_app}/images/hainan/ico_word.gif) no-repeat;padding-left:5px;\"></span><\/a>";
							}
							}
						}
						tr +="</td>";
						if(vo.noteTitle!=null){
							tr += "<td align=\"center\" id=\"tips_" + vo.grantCode + "\" onmouseover=\"showTips(" + vo.grantCode + ")\">";
							tr += "<span>" + vo.noteTitle + "</span>";
							tr += "<input id=\"note_" + vo.grantCode + "\" type=\"hidden\" value=\"" + vo.noteContent + "\">";
							tr += "</td>";
						} else
							tr += "<td></td>";
						
						tr += "<td>";
						tr += "<div name='tips_msg' style='display:none'><span name='tips'>"+vo.stat_year+"年度资助预算额度为"+(vo.award_amt?vo.award_amt:0)+"万元。截至目前，系统已接受申请书"+(vo.receive_cnt?vo.receive_cnt:0)+"份,申请金额共计"+(vo.submit_amt?vo.submit_amt:0)+"万元"+"</span><div style='text-align:center;margin-top: 30px'><input type='button'  name='btnConfirm' value='进入申报'  style=\"background-color:#FFE6D4;color:#CC0000\" onclick=\"enterPrp('" + parentCode + "','" + vo.grantCode + "','" + flag + "')\"></div></div>";
						if(vo.enabled=='1' && vo.startDateLong && vo.endDateLong>=vo.currentDateLong)
						tr += "<input type=\"button\" class=\"btn_fill\" title=\"填写申请\" onclick=\"showMsg(this,'"+vo.grantName+"');\"/>";
						 
						tr += "</td>";
						tr += "</tr>";
					}else
						{
						//trObj.attr("prpFlag","1");
						tr += "<tr  parentCode='" + parentCode + "' grandParentCode='" + grandParentCode + "' id='tr_"+vo.grantCode+"_"+parentCode+"'class='bg_c'  onclick='showChildGrant("+parentCode+","+vo.grantCode+","+1+")'>";
						tr += "<td nowrap>&nbsp;&nbsp;&nbsp;<a href='###' id=name_"+vo.grantCode+"_"+parentCode+" class='b_Close_julei'  >"+vo.grantName+"</a></td>";
						tr += "<td class='num' align='center'>";
						tr += "</td>";
						tr += "<td >";
						tr += "	<span></span>";
						tr += "</td>";
						tr += "<td >";
						tr += "	<span></span>";
						tr += "</td>";
						tr += "<td>";
						tr += "<input type='button' class='btn_zk' title='展开' id='btn_"+vo.grantCode+"_"+parentCode+"'/>";
						tr += "</td>";
						tr += "</tr>";
						}
				}
				
				trObj.after(tr);		//将子类加到本行后面
				trObj.attr("init","1");
				//trObj.attr("openFlag","1");
				if(prpFlag == "1"){
					$("#name_"+parentCode+"_"+grandParentCode).attr("class","b_Open_julei");
				}else{
					$("#name_"+parentCode+"_"+grandParentCode).attr("class","b_Open");
				}
				$("#btn_"+parentCode+"_"+grandParentCode).attr("class","btn_gb");
				$("#btn_"+parentCode+"_"+grandParentCode).attr("title","收缩");
				updateTabView();
			},
			error : function() {
				scmError("加载失败");
			}
		});
		prcWin.closeWin();
	}
	
	
	function showMsg(obj,grantName){
		//var msg = $(obj).parent("td").find("div[name='tips_msg']").html();
		 //showBox($(obj),100,50,grantName+"申报情况",msg);
		// if(window.confirm($(obj).parents("td").find("span[name=tips]").html())){
			 $(obj).parents("td").find("input[name=btnConfirm]").click();
		// }
	}
	function updateTabView(){
		$("table[id^='fragment-tab'] tr:not(:first):even").css("background", "#fff");
		$("table[id^='fragment-tab'] tr:not(:first):odd").css("background", "#f5faff");
		$("table[id^='fragment-tab'] tr:not(:first)").hover(
				function() {
					$(this).css("background", "#deebf9");
				},
				function() {
					$(this).css("background", $(this)[0].rowIndex % 2 == 0 ? "#f5faff" : "#fff");
			});
		
	}
	function showRes(pos){
 		//alert("${res_app}/"+pos);
 		if(pos!='')
 		window.open("${res_app}/sample/"+encodeURIComponent(pos));
 		// top.location = "${res_app}/"+pos;
 		return false;
 	}
	function downLoadRes(url){
 		if(url!='')
 	 		window.open(url);
 	    return false
 	}
	
</script>
</body>
</html>